<template>
	<view>
		<view class="top" @click.capture="maskFalse">
			<view class="one">
				<view class="left" v-if="allData.playlist">
					<image :src="allData.playlist.coverImgUrl" mode=""></image>
				</view>
				<view class="right" v-if="allData.playlist">
					<text>{{allData.playlist.name}}</text>
					<text>{{allData.playlist.creator.nickname}}</text>
				</view>
			</view>
			<view class="two">
				<view class="cons">
					<image src="../../img/pinglun.png" mode=""></image>
					<text>评论</text>
				</view>
				<view class="cons">
					<image src="../../img/dianzan.png" mode=""></image>
					<text>点赞</text>
				</view>
				<view class="cons">
					<image src="../../img/jiahao_o.png" mode=""></image>
					<text>收藏</text>
				</view>
				<view class="cons">
					<image src="../../img/gengduo-shuxiang.png" mode=""></image>
					<text>更多</text>
				</view>
			</view>
		</view>

		<view @click.capture="maskFalse" class="list1" v-if="allData.playlist">
			<musicList  v-for="(item,index) in allData.playlist.tracks" :key="index" :img="index+1"
				:nameValue="item.name" :describe="item.al.name" :id="item.id" @playAudio="playAudio"></musicList>
		</view>

		<!-- 底部的播放器 -->
		<template v-if="allData.playlist && val != ''">
			<musicTabbar  @listTrue="listTrue" :flag="flag" :mp3="mp3" :title.sync="val"
				:play="true" :listIndex="i" :list="allData.playlist.tracks" @toMp3="toMp3" :desc="desc" :url="img"></musicTabbar>
		</template>

	</view>
</template>

<script>
	import {
		getSongList,
		getMpthree
	} from '@/api/music.js';
	import musicTabbar from '@/components/musicTabbar/musicTabbar.vue'
	import musicList from '@/components/musicList/musicList.vue';
	export default {
		data() {
			return {
				id: 0,
				allData: {}, //当前页面的所有的数据
				flag: false,//右边的列表的显示隐藏
				onlyData: {}, //点击的那一条音乐
				i: 0,//列表的点击第几个的下标
				val: '',//底部标题
				mp3:"",//mp3文件
				desc:"",//描述
				img:"",//底部的图片
			};
		},
		onLoad(options) {
			// console.log(options.id);
			this.id = options.id
		},
		created() {
			// 获取音乐列表的数据
			getSongList(this.id).then(res => {
				console.log(res);
				this.allData = res.data;
			})
		},
		components: {
			musicTabbar,
			musicList
		},
		methods: {
			maskFalse() {
				this.flag = false;
			},
			listTrue() {
				this.flag = true;
				console.log(this.flag);
			},
			playAudio(id) {
				
				this.i = this.allData.playlist.tracks.findIndex(item => item.id == id)
				console.log(this.i );
				this.val = this.allData.playlist.tracks[this.i].name
				this.desc = this.allData.playlist.tracks[this.i].al.name;
				console.log(this.allData.playlist.tracks[this.i].al.name);
				this.img = this.allData.playlist.tracks[this.i].al.picUrl;
				getMpthree(id).then(res => { //获取mp3文件的
					// console.log(res.data);
					this.onlyData = res.data.data[0];
					this.mp3 = this.onlyData.url
				})
			},
			toMp3(obj){
				this.mp3 = obj.mp3;
				this.val = obj.title;
				this.img = obj.img;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.top {
		width: 750rpx;
		height: 430rpx;
		padding: 20rpx;
		box-sizing: border-box;
		background: linear-gradient(to right, #3c3e55, #a18377);

		.one {
			height: 250rpx;
			display: flex;
			align-items: center;

			.left {
				width: 230rpx;
				height: 230rpx;

				>image {
					width: 100%;
					height: 100%;
				}
			}

			.right {
				width: 460rpx;
				height: 200rpx;
				padding: 30rpx 0 0 30rpx;
				box-sizing: border-box;
				display: flex;
				align-content: space-between;
				flex-wrap: wrap;

				>text {
					width: 100%;
				}

				>text:nth-of-type(1) {
					font-size: 40rpx;
					font-weight: bolder;
					color: #fff;
				}

				>text:nth-of-type(2) {
					font-size: 24rpx;
					color: #999;
				}
			}

		}

		.two {
			width: 750rpx;
			height: 150rpx;
			display: flex;
			align-items: center;
			justify-content: space-around;
			.cons {
				width: 140rpx;

				>image {
					width: 70rpx;
					height: 70rpx;
					display: block;
					margin: 0 auto;
				}

				>text {
					display: block;
					text-align: center;
					padding-top: 10rpx;
					color: #f2f2f2;
					font-size: 24rpx;
				}
			}
		}
	}
	.list1{
		padding-bottom: 120rpx;
	}
</style>
